{% extends "base.html" %}
{% import '/forms/form_macro.html' as form_template %}

{% if not current_node %}
    {% set has_submit=False %}
{% endif %}


{% if task is none or task.status==1 %}
    {% set has_submit=True %}
{% endif %}

{% block content %}


    <form readonly
            {% if task %}
                action="/flow/post_form/{{ task.tid }}/"
            {% else %}
                action="/flow/create_form/{{ flow.fid }}/"
            {% endif %}

                method="POST">

        <div class="row">
            <div class="col-md-3">&nbsp;</div>
            <div class="col-md-6">
                {% include 'message.html' %}
                {% block form_title %}
                                    <div class="row" style="text-align: center">
                    <a href="/flow/flow_chart/{{ flow.fid }} " target="_blank"><h3>{{ flow.name }} </h3></a>
                    <p>
                        <span> 提交人: {{ submitter.account }}({{ submitter.name }})</span>
                        <span> </span>
                    </p>
                </div>
                {% endblock %}
                {% block form_body %}
                    {{ form_template.quick_form(form,form_type='horizontal',horizontal_columns=('lg', 2, 8),has_submit=has_submit) }}
                {% endblock %}
                {% block form_bottom %}
                {% endblock %}

                <div class="row" style="text-align: right; ">
                </div>
{#                <p>&nbsp;</p>#}
                <div class="row" style="text-align: center;">
                    {% if current_user.uid in approvers %}
                        {% if current_node.has_pass %}
                            <a href="/flow/approve_form/passed/{{ process.id | default('0') }}"
                               class="btn btn-default btn-sm" role="button" type="submit">同意
                            </a>
                        {% endif %}
                        {% if current_node.has_reject %}
                            <a href="/flow/approve_form/rejected/{{ process.id | default('0') }}"
                               class="btn btn-default btn-sm" role="button" type="submit">拒绝
                            </a>
                        {% endif %}
                        {% if current_node.has_return %}
                            <a href="/flow/approve_form/returned/{{ process.id | default('0') }}"
                               class="btn btn-default btn-sm" role="button" type="submit">退回
                            </a>
                        {% endif %}
                        {% if current_node.has_void %}
                            <a href="/flow/approve_form/voided/{{ process.id | default('0') }}"
                               class="btn btn-default btn-sm" role="button" type="submit">作废
                            </a>
                        {% endif %}
                    {% endif %}
                </div>
                <p>&nbsp;</p>
            </div>
            <div class="col-md-3">&nbsp;</div>
        </div>
    </form>
    {% block approval_history %}
        <div class="row">
            <div class="col-md-3">&nbsp;</div>
            <div class="col-md-6">
                {% if process_list %}
                    <table class="table">
                        <thead>
                        <tr>
                            <th>审批人</th>
                            <th>审批节点</th>
                            <th>创建时间</th>
                            <th>提交时间</th>
                            <th>{% if task_status(task.status) == 'completed' %}
                                <span style="color: red">已结束</span>
                            {% else %}<span style="color: blue">{{ task_status(task.status) }}</span> {% endif %}</th>
                        </tr>
                        </thead>
                        <tbody>

                        {% for item in process_list %}
                            {% if item.uid %}
                                <tr>
                                    <td>{{ item.user.account }}({{ item.user.name }})</td>
                                    <td>{{ item.node.name }} </td>
                                    <td>{{ item.create_date }} </td>
                                    <td>{% if user_action(item.action) != 'init' %}{{ item.update_date }}{% endif %} </td>
                                    <td>
                                        {% if user_action(item.action) == 'passed' %}
                                            <span style="color: green;">passed</span>
                                        {% elif user_action(item.action) == 'rejected' %}
                                            <span style="color: red;">rejected</span>
                                        {% else %}
                                            {{ user_action(item.action) }}
                                        {% endif %}
                                    </td>
                                </tr>
                            {% endif %}
                        {% endfor %}

                        </tbody>
                    </table>
                {% endif %}
            </div>
        </div>
        <div class="col-md-3">&nbsp;</div>
    {% endblock %}
    </div>

{% endblock %}